
unset(WRAP_ITK_MODULES CACHE)

if(ITK_SOURCE_DIR)
  foreach(m ${ITK_CONFIG_MODULES_ENABLED})
    if(EXISTS "${${m}_SOURCE_DIR}/wrapping/CMakeLists.txt")
      list(APPEND WRAP_ITK_MODULES ${m})
      set(itk-module_SOURCE_DIR ${${m}_SOURCE_DIR})
      add_subdirectory("${${m}_SOURCE_DIR}/wrapping" ${CMAKE_CURRENT_BINARY_DIR}/${m})
      unset(itk-module_SOURCE_DIR)
    endif()
  endforeach()
else() # Building a module externally
  if(EXISTS "${${itk-module}_SOURCE_DIR}/wrapping/CMakeLists.txt")
    foreach(module ${ITK_MODULE_${itk-module}_DEPENDS})
      if(EXISTS ${WRAPPER_MASTER_INDEX_OUTPUT_DIR}/${module}.mdx)
        list(APPEND WRAP_ITK_MODULES ${module})
      endif()
    endforeach()
    list(APPEND WRAP_ITK_MODULES ${itk-module})
    add_subdirectory("${${itk-module}_SOURCE_DIR}/wrapping" ${CMAKE_CURRENT_BINARY_DIR}/${itk-module})
  endif()
endif()
set(WRAP_ITK_MODULES ${WRAP_ITK_MODULES} CACHE INTERNAL "Internal library list.")
